package com.example.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.example.common.result.Result;
import com.example.common.result.YiFeiException;
import com.example.entity.yifei.Coptg;
import com.example.entity.yifei.Copth;
import com.example.mapper.CoptgMapper;
import com.example.mapper.CopthMapper;
import com.example.service.CoptgService;
import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

/**
* @author 14501
* @description 针对表【COPTG】的数据库操作Service实现
* @createDate 2024-08-06 13:51:44
*/
@Service
public class CoptgServiceImpl extends ServiceImpl<CoptgMapper, Coptg>
    implements CoptgService{

    @Resource
    private CoptgMapper coptgMapper;
    @Resource
    private CopthMapper copthMapper;

    @Override
    public Result queryIPage(Integer current, Integer size) {
        try{
            Map<String,Object> map = new HashMap<>();
            IPage<Coptg> iPage = new Page<>(current,size);
            IPage<Coptg> coptgIPage = this.coptgMapper.selectPage(iPage, null);
            map.put("pages", coptgIPage.getPages());
            map.put("total", coptgIPage.getTotal());
            map.put("list", coptgIPage.getRecords());
            return Result.success(map);
        }catch (Exception e){
            throw new YiFeiException(500,"销货单单头查询发生异常"+e.getMessage());
        }
    }

    @Override
    public Result queryList(String tg001, String tg002) {
        try{
            List<Copth> copthList = this.copthMapper.selectList(new LambdaQueryWrapper<Copth>().eq(Copth::getTH001, tg001).eq(Copth::getTH002, tg002));
            return Result.success(copthList);
        }catch (Exception e){
            throw new YiFeiException(500,"销货单单身查询发生异常"+e.getMessage());
        }
    }

    @Override
    public Result<PageInfo<List<Coptg>>> queryIPage3(Integer current, Integer size) {
        PageHelper.startPage(current, size);
        List<Coptg> list = this.copthMapper.selCoptgPlus();
        PageInfo<List<Coptg>> pageInfo = new PageInfo(list);
        return Result.success(pageInfo);
    }
}




